package com.sw.service;

import com.github.pagehelper.PageInfo;
import com.google.gson.Gson;
import com.sw.domain.FullActive;
import com.sw.domain.FullActivePage;
import com.sw.mapper.ActiveEnrollMapper;
import com.sw.mapper.ActiveMapper;
import com.sw.mapper.OriginatorMapper;
import com.sw.model.Active;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2017/8/3.
 */
@Service
public class ActiveService {
    @Autowired
    private OriginatorMapper originatorMapper;
    protected Logger log= LoggerFactory.getLogger(getClass());
    Gson gson = new Gson();

    public FullActivePage getFullActivePage(List<Active> activeList){
        List<FullActive> fullActiveList=new ArrayList<>();
        FullActivePage fullActivePage=new FullActivePage();
        PageInfo<Active> pageInfo=new PageInfo<Active>(activeList);

        // 组装返回结果
        for (int i =0;i<activeList.size();i++){
            Active active=activeList.get(i);
            FullActive fullActive=new FullActive();
            BeanUtils.copyProperties(active,fullActive);
            fullActive.setOriginatorName(originatorMapper.selectByPrimaryKey(active.getOriginatorId()).getOriginatorName());
            fullActiveList.add(fullActive);
        }
        fullActivePage.setFullActiveList(fullActiveList);
        fullActivePage.setPageCount(pageInfo.getPages());
//        log.debug("pageInfo={}",gson.toJson(pageInfo));
        return fullActivePage;
    }
}
